<template>
    <div id="productlist">
        <!-- <button @click="getscenicProductList">获取雪场产品列表</button> -->
        <div class="pdt_header">
            <div class="snow_name"><span class="el-icon-s-cooperation"></span><span class="zjk_snow">{{name}}</span>
            </div>
        </div>

        <ul class="pdt_btn">
            <li>
                <el-button type="danger" @click='deletAll'>删除</el-button>
            </li>
            <li>
                <el-button type="primary" @click="useflagall">下架</el-button>
            </li>
        </ul>
        <div class="pdt_table">
            <el-table @selection-change="checkAll"
                :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" style="width: 100%"
                tooltip-effect="dark">


                <el-table-column type="selection" width="55">
                </el-table-column>


                <el-table-column prop="sort" label="排序" width="50">
                </el-table-column>
                <el-table-column prop="productid" label="产品ID号" width="180">
                </el-table-column>
                <el-table-column prop="productname" label="产品名称" width="300">
                </el-table-column>
                <el-table-column prop="sale_count" label="已售数量" width="100">
                </el-table-column>
                <el-table-column prop="created_at" label="创建时间" width="300">
                </el-table-column>
                <el-table-column prop="useflag" label="上架" width="100">
                </el-table-column>
                <el-table-column prop="returnflag" label="是否可退" width="100">
                </el-table-column>
                <el-table-column prop="address" label="操作">
                    <template slot-scope="scope">
                        <el-button @click="handleClick(scope.row)" type="text" size="small">详情</el-button>

                        <el-button @click="sonwlistputaway(scope.row)" type="text" size="small"
                            v-if='scope.row.useflag==0'>上架</el-button>
                        <el-button @click="sonwlistputaway(scope.row)" type="text" size="small" v-else>下架</el-button>
                        <el-button @click="snowlistdelete(scope.row)" type="text" size="small"><span
                                class="btn_delete">删除</span></el-button>
                    </template>
                </el-table-column>
            </el-table>

        </div>
        <div class="block">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page.sync="currentPage1" :page-size="pagesize" background layout="total, prev, pager, next"
                :total="total">
            </el-pagination>
        </div>


    </div>
</template>
<script>
    import { getscenicProductList, getchangeUseFlag } from "../request/index"
    export default {
        data() {
            return {
                //多选的id字符串
                strIds: '',
                count: '',
                cardtf: false,
                pageChecked: true,
                input1: "",
                sousuok: false,

                multipleSelection: [],
                total: 10,
                pagesize: null,
                currentPage: 1,
                currentPage1: 5,
                name: "",
                currentPage2: 5,
                currentPage3: 5,
                currentPage4: 4,
                tableData: [{
                    sort: "",
                    select: "",
                    productid: '',
                    productname: '',
                    sold: '',
                    time: "",
                    putaway: "",
                    returnable: "",
                    scenicId: ""
                },]
            }
        },
        methods: {
            //批量上下架
            useflagall(){
                // console.log(111);
                let data={
                    id: this.strIds,
                    useflag: 3
                }
                getchangeUseFlag().then(res=>{
                    console.log(res);
                })
            },
            //批量删
            deletAll() {

                if (this.strIds == '') {
                    this.$message({
                        message: "请选择要删除的数据",
                        type: 'error'
                    })
                    return
                }
                this.$confirm('此操作将永久删除该产品, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let data = {
                        id: this.strIds,
                        useflag: 3
                    }
                    getchangeUseFlag(data).then(res => {
                        console.log(res);
                        if (res.code == "666") {
                            this.$message({
                                message: res.msg,
                                type: 'success'
                            })
                        } else {
                            this.$message({
                                message: res.msg,
                                type: 'error'
                            })
                        }
                        this.getscenicProductList()
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });


            },
            //多选
            checkAll(v) {
                console.log(v);
                let str = []
                v.forEach(item => {

                    str.push(item.productid)
                })

                this.strIds = str.join(',')
                console.log(this.strIds);
            },
            //上架下架
            sonwlistputaway(row) {
                this.$confirm('是否上下架该产品?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let data = {
                        id: row.productid,
                        useflag: row.useflag ? 0 : 1
                    }
                    getchangeUseFlag(data).then(res => {
                        this.getscenicProductList()
                        console.log(res);
                        if (res.code == "666") {
                            this.$message({
                                message: res.msg,
                                type: 'success'
                            })
                        } else {
                            this.$message({
                                message: res.msg,
                                type: 'error'
                            })
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
                // console.log(1111);
                console.log(row.useflag);


            },
            //删除
            snowlistdelete(row) {
                this.$confirm('此操作将永久删除该产品, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {

                    let data = {
                        id: row.productid,
                        useflag: 3
                    }
                    getchangeUseFlag(data).then(res => {
                        console.log(res);
                        if (res.code == "666") {
                            this.$message({
                                message: res.msg,
                                type: 'success'
                            })
                        } else {
                            this.$message({
                                message: res.msg,
                                type: 'error'
                            })
                        }
                        this.getscenicProductList()
                    })


                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                getscenicProductList({ page: val }).then(res => {
                    console.log(res);
                    this.tableData = res.list
                })
            },
            getscenicProductList() {
                console.log(111);
                this.scenicId = this.$route.query
                console.log(this.scenicId);
                getscenicProductList({ scenicId: this.scenicId.id }).then(res => {
                    console.log(res.scenicName);
                    this.tableData = res.list
                    console.log(res.list);
                    this.pagesize = res.pageSize
                    this.total = res.count
                    console.log(this.total);
                    this.name = res.scenicName
                })
            },
            current_change: function (currentPage) {
                this.currentPage = currentPage;
            },
        },
        mounted() {
            this.getscenicProductList()
        }
    }
</script>
<style scoped>
    .btn_delete {
        color: red;
    }

    #productlist {
        width: 1660px;
        height: 800px;
        /* background-color: red; */
        margin-top: 15px;
    }

    .pdt_header {
        width: 100%;
        height: 60px;
        background-color: #fff;
        overflow: hidden;
    }

    .el-icon-s-cooperation {
        font-size: 30px;
        color: #2A78FF;
        vertical-align: baseline;
    }

    .block {
        position: absolute;
        bottom: 30px;
        left: 820px;
    }

    .zjk_snow {
        font-size: 22px;
        font-weight: 700;
    }

    .snow_name {
        margin-top: 10px;
        margin-left: 10px;
    }

    .pdt_btn>li {
        float: right;
        margin-left: 20px;
        margin-top: 15px;
    }

    .pdt_table {
        width: 100%;
        height: 680px;
        /* background-color: skyblue; */
        margin-top: 60px;
    }
</style>